﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GUI
{
    public partial class MainView : Form
    {
        public MainView()
        {
            InitializeComponent();
        }

        #region event

        private void homeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tabMian.SelectedIndex = 0;
        }

        private void saleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoadTabPage("tabSale", "Sale",new PRDT001());                
        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            if (tabMian.SelectedTab.Name == "tabHome")
                return;
            tabMian.SelectedTab.Dispose();
            tabMian.SelectedIndex = tabMian.TabCount - 1;
        }

        #endregion
 
        #region private method

        private void LoadTabPage(string name, string text, UserControl usc)
        {
            if (tabMian.TabCount == 5)
            {
                tabMian.SelectedIndex = 1;
                tabMian.SelectedTab.Dispose();
            }
            
            foreach (TabPage item in tabMian.TabPages)
            {
                if (item.Name == name)
                {
                    tabMian.SelectedTab = item;
                    return;
                }
            }
            TabPage tabPage = CreateTabPage(name, text);
            usc.Dock = DockStyle.Fill;
            tabPage.Controls.Add(usc);            
            tabMian.SelectedTab = tabPage;
        }

        private TabPage CreateTabPage(string name, string title)
        {
            TabPage tabPage = new TabPage();
            tabPage.Name = name;
            tabPage.Padding = new System.Windows.Forms.Padding(3);
            tabPage.Size = new System.Drawing.Size(587, 311);
            tabPage.Text = title;
            tabPage.UseVisualStyleBackColor = true;
            tabMian.Controls.Add(tabPage);
            return tabPage;
        }

        #endregion
    }
}
